package org.btik.light.mobile.ui.factory;

import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import org.btik.light.mobile.R;
import org.btik.light.mobile.meta.mo.DefaultDevMo;
import org.btik.light.mobile.meta.DevMeta;
import org.btik.light.mobile.meta.DevModel;

import java.util.Objects;


public abstract class DevPanel<T extends DevModel> extends Fragment {

    /**
     * 设备
     */
    protected DefaultDevMo dev;

    protected T model;

    public DevPanel(DefaultDevMo dev) {
        this.dev = dev;
    }

    private FragmentActivity updateTitleFromMo(int devTypeId){
        FragmentActivity activity = getActivity();
        Objects.requireNonNull(activity);
        String devType = activity.getString(devTypeId);
        Toolbar actionBar = activity.findViewById(R.id.action_bar);
        actionBar.setTitle(devType +'|' +dev.getDisplayName());
        return activity;
    }

    protected void bindModel(){
        DevMeta meta = model.getMeta();
        updateTitleFromMo(meta.devTypeResStringId());
    }
}
